<%-- 
  - Author: Abed Yaseen
  - Date: 02-Jan-2012
  - Copyright Notice: TRAKHEES
  - Description: show.jsp
 --%>
<%@ include file="/WEB-INF/view/include.jsp"%>

<div id="search_container">
      <div class="t_search_heading"><spring:message code="label.notification.search" /></div>
     <form>
      <div class="t_search-left">
      	<label class="label-search"><spring:message code="grid.columnname.notification_no" /></label>
        <input name="NotificationNo" id="NotificationNo" type="text" class="t_form-fld" />
        <div class="clear"></div>
        <label class="label-search"><spring:message code="label.reference_no" /></label>
        <input name="referenceNo" id="referenceNo" type="text" class="t_form-fld" />
      </div>
      <div class="t_search-right">
        <label class="label-search"><spring:message code="label.service_name" /></label>
        <input name="serviceName" id="serviceName" type="text" class="t_form-fld" />
        
        <label for="displayReaded" class="label-search"><spring:message code="label.display_read" /></label>
        <input type="checkbox" name="displayReaded" id="displayReaded" onchange="gridReload();" style="margin:5px 0 0 0; float:left;" />
      </div>
      
      <div class="t_search_btns">
        <button type="button" onclick="gridReload()" id="submitButton" class="button_small" ><spring:message code="button.search" /></button>
        <button type="reset"  class="button_small" ><spring:message code="button.reset" /></button>
      </div>
   </form>   
      
 </div>
 <BR />
 <div id="NotificationsGrid" style="width: 718px;">
	 <table id="listemployee"></table> 
	 <div id="pager"></div>
 </div>
  
 <script>
	jQuery(document).ready(function() {
	
	$(".topnav").accordion({
		accordion:false,
		speed: 500,
		closedSign: '<img src=\'resources/images/common/close.jpg\' />',
		openedSign: '<img src=\'resources/images/common/open.jpg\' />'
	});
	
	$(document).keypress(function(e) {
		if (e.keyCode == 13) {
			gridReload();
		}
	});
 
	$('#listemployee').jqGrid({
					datatype :'json',
					url		 :'displayUserNotification.json',
					colNames : [ '<spring:message code="grid.columnname.notification_no" />',
						  		 '<spring:message code="grid.columnname.service_name" />',
						  		 '<spring:message code="grid.columnname.reference_no" />',
						  		 '<spring:message code="grid.columnname.subject" />',
						  		 '<spring:message code="grid.columnname.date_received" />',
						  		 '<spring:message code="grid.columnname.attachment" />',
						  		 '<spring:message code="grid.columnname.url" />'
						  		] ,
					
					colModel : [
					  {name:'id',index:'id', width:55, sortable:false}, 
					  {name:'servicename',index:'servicename', width:150, align:"left",sortable : true}, 
					  {name:'reference',index:'reference', width:80,sortable : true}, 
					  {name:'subject',index:'subject', width:100, sortable : true}, 
					  {name:'receivedon',index:'receivedon', width:150, sortable : true},
					  {name:'attachment',index:'attachment', width:150, sortable : true},
					  {name:'url',index:'url', width:150, align:"center", sortable : true}
					 ],
					height:300,
					rowNum: 15,
					autowidth: true, 
					viewrecords: true,
					rowList:[10,20,30], 
					pager: jQuery('#pager'), 
					sortname: 'id', 
					viewrecords: true, 
					sortorder: "asc", 
					hidegrid: false,
					caption : '<spring:message code="menu.label.notifications" />'
					<c:if test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
					, direction:'rtl'
					</c:if>									
				});	
	
		
		setInterval(function(){  gridReload(); },60000);
	});

	 var addressFormatting = function(text){
				var newText = text;
				//array of find replaces
				var findreps = [
					{find:/^([^\-]+) \- /g, rep: '<span class="ui-selectmenu-item-header">$1</span>'},
					{find:/([^\|><]+) \| /g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
					{find:/([^\|><\(\)]+) (\()/g, rep: '<span class="ui-selectmenu-item-content">$1</span>$2'},
					{find:/([^\|><\(\)]+)$/g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
					{find:/(\([^\|><]+\))$/g, rep: '<span class="ui-selectmenu-item-footer">$1</span>'}
				];
				
				for(var i in findreps){
					newText = newText.replace(findreps[i].find, findreps[i].rep);
				}
				return newText;
	}
	
	function gridReload(){
	
		 var referenceNo = jQuery("#referenceNo").val();
		 var NotificationNo = jQuery("#NotificationNo").val();
		 var serviceName = jQuery("#serviceName").val();
		 var displayReaded = false;
		 if($("#displayReaded").attr("checked")){
			 displayReaded = true;
		 }
		 
		 jQuery("#listemployee").jqGrid('setGridParam',
		 							{url:"displayUserNotification.json?referenceNo="
		 								+referenceNo
		 								+"&serviceName="+serviceName
		 								+"&notificationId="+NotificationNo
		 								+"&displayReaded="+displayReaded
										,page:1}
		 							   ).trigger("reloadGrid");
    }
		
</script>